//
//  LCAppDelegate+AddRootVC.m
//  lgbt
//
//  Created by jiukuyinyue on 2017/11/2.
//  Copyright © 2017年 lgbt. All rights reserved.
//

#import "LCAppDelegate+AddRootVC.h"

@implementation LCAppDelegate (AddRootVC)

#pragma mark - 配置引导页和主页
-(void)setupApplication:(NSString *)clzName{
    Class clz = NSClassFromString(clzName);//将字符串转化成class
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    self.window.backgroundColor = [UIColor whiteColor];//windows底色为白色
    UITabBarController *tabBarController = [[clz alloc] init];
    //引导页判断
    //    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Guide" bundle:nil];
    //    UIViewController *controller = [sb instantiateInitialViewController];
    //    self.window.rootViewController = [self selectRoot] ? controller :tabBarController;
    
    //无引导页
    self.window.rootViewController = tabBarController;
    
    [self.window makeKeyAndVisible];
}

#pragma mark - 首启动根控制器选择
- (Boolean)selectRoot{
    //根据版本号判断是否首次启动,选择启动控制器
    NSUserDefaults* defaulut = [NSUserDefaults standardUserDefaults];
    
    // 获取当前的手机应用的版本号
    NSDictionary* dict = [NSBundle mainBundle].infoDictionary;
    NSString* appVersion = dict[@"CFBundleShortVersionString"];
    
    // 获取上一次手机的版本号
    NSString* lastVersion = [defaulut objectForKey:@"appVersion"];
    
    //    UIViewController * mainController;
    
    [defaulut setObject:appVersion forKey:@"appVersion"];
    [defaulut synchronize];
    
    //判断版本号,选择控制器
    if (![lastVersion isEqualToString:appVersion]) {
        NSLog(@"第一次启动");
        return true;
    }
    
    return false;
    
}

@end
